package com.qen.yanggao

import cn.hutool.db.Db
import cn.hutool.poi.excel.ExcelUtil

fun main() {
    val inTbale = ArrayList<String>()
    for (str in tableList) {
        inTbale.add("'${str}'")
    }
    val list = Db.use().query("select * from SCHEMATA where SCHEMA_NAME in (${inTbale.joinToString(",")})")
    val rows = ArrayList<SchemaAll>()
    for (entity in list) {
        rows.add(
            SchemaAll(
                code = "utf8",
                nameChi = "",
                nameEng = entity.getStr("schema_name"),
                schemaCode = entity.getStr("default_character_set_name"),
                type = "Mysql",
                desc = ""
            )
        )
    }
    outExcel(rows)
}

data class SchemaAll(
    val code: String = "utf8",
    val nameChi: String = "",
    val nameEng: String = "",
    val schemaCode: String = "",
    val type: String = "",
    val desc: String = ""
)

fun outExcel(rows: ArrayList<SchemaAll>) {
    val writer = ExcelUtil.getWriter("${OutPath}3数据表登记导入模板Sheet1.xlsx")
    writer.addHeaderAlias("code", "系统编码（必填）")
    writer.addHeaderAlias("nameChi", "数据库中文名称（必填）")
    writer.addHeaderAlias("nameEng", "数据库英文名称（必填）")
    writer.addHeaderAlias("schemaCode", "数据库字符集编码（必填）")
    writer.addHeaderAlias("type", "数据库类型（必填）")
    writer.addHeaderAlias("desc", "数据库描述（必填）")

    writer.write(rows, true)
    writer.close()
}